<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@page import="user.User"%>
<%@page import="java.util.ArrayList"%>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
        <title></title>
        <meta name="description" content="">
        <meta name="viewport" content="width=device-width">

        <link rel="stylesheet" href="css/bootstrap.min.css">
        <style>
            body {
                padding-top: 60px;
                padding-bottom: 40px;
            }
        </style>
        <link rel="stylesheet" href="css/bootstrap-responsive.min.css">
        <link rel="stylesheet" href="css/main.css">

        <!--[if lt IE 9]>
            <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
            <script>window.html5 || document.write('<script src="js/vendor/html5shiv.js"><\/script>')</script>
        <![endif]-->
    </head>
      <body id = "b1">
   
			
      <%String u = (String)request.getSession().getAttribute("user");
      	if(u!=null){
      		if(!u.equalsIgnoreCase("admin")){
      			request.setAttribute("Reset","7mada");
				request.getRequestDispatcher("/index.jsp").forward(request, response);
				
      		}
      	}else{
      		request.setAttribute("Reset","wassim");
			request.getRequestDispatcher("/index.jsp").forward(request, response);
      	}
      		
      %>
      
 	    <div class="container">
 	      
		<div class="row">
		
			
			
			
			<div class="span7 offset2 well">
					<span class="pull-left">Car Auction - Users</span>
					<button class="btn btn-small btn-primary pull-right" type="submit">Logout</button>
			</div>
			<div class="span7 offset2 well">
			 <% String x = (String)request.getAttribute("Reset");
 	      String z =(String)request.getAttribute("register");
				%>
			
			<% if( x!=null) { %>
  			<div class="alert alert-error">
			  <button type="button" class="close" data-dismiss="alert">&times;</button>
 				<%
				if(x != null )
					out.print(x);
 				
					%>	
					
			</div>
			<% } %>
			<% if( z!=null) { %>
  			<div class="alert alert-success">
			  <button type="button" class="close" data-dismiss="alert">&times;</button>
 				<%
				if(z != null )
					out.print(z);
 					%>	
					
			</div>
			<% } %>
			<div id="tableWrap" style="height:306px;overflow-y: scroll; margin-bottom:10px;">
				<% ArrayList<User> users = (ArrayList<User>)request.getAttribute("table"); %>
				
				<table class="table table-striped">
				  <thead>
					<tr>
					  <th>Username</th>
					  <th>Credi Card Number</th>
					</tr>
				  </thead>
				  <tbody>
					<% for(int i = 0 ; i < users.size();i++){   %>
					<tr>
						  <td><c:out value="<%=users.get(i).getUserName() %>"/></td>
						  <td><c:out  value ="<%=users.get(i).getCreditCardNumber()%>" /></td>
				
					</tr>
					<%} %>
				  </tbody>
				</table>
				</div>
			  	<form id="private" class="form-signin">
			  	
					<input type="text" id="privateKey" name="privateKey" class="input-block-level" placeholder="Your Private Key">
					<br>
					<button class="btn btn-medium btn-primary" type="submit">Decrypt</button>
				</form>
			</div>
	    </div>
		</div> <!-- /container -->

		<script src="js/jquery-1.9.1.min.js"></script>
		<script src="js/jquery.validate.js"></script>
        <script src="js/vendor/bootstrap.min.js"></script>
        <script src="js/main.js"></script>
		<script type="text/javascript">
			$(document).ready(function(){
				$("#private").validate({
					rules:{
						privateKey:"required",
					},
				});
		
			
				$("#private").submit(function(event){
					if($("#private").valid()){ 
					 	var $form = $(this),
				      $inputs = $form.find("input, select, button, textarea"),
				      serializedData = $form.serialize();  
				     $inputs.attr("disabled", "disabled");
				    
				     $.ajax({
				      url: "Security?action=decryptPasswords",
				      type: "post",
				      data: serializedData,
				      success: function(response, textStatus, jqXHR,formID){
				    	  $("#b1").html(response); 
				      },
				      error: function(jqXHR, textStatus, errorThrown){
				      	console.log("The following error occured: "+textStatus, errorThrown);
				      },
				      complete: function(){
				   	   $inputs.removeAttr("disabled");
				    	 
				      }
				     
				  });	
					}
					 
					 event.preventDefault(); 	  
				});
			
			});
		</script>
    </body>
</html>
